package util

import (
	"golang.org/x/crypto/bcrypt"
)


// md5 加密
func Encrypte(password string) (string, error) {
	hashedPasswordBytes, err := bcrypt.GenerateFromPassword([]byte(password), bcrypt.DefaultCost)
	if err != nil {
		return "", err
	}
	hashedPassword := string(hashedPasswordBytes)
	return hashedPassword, nil
}

// 验证是否相同
func ValidRawPasswordCorrect(hashedPassword, userPassword string) bool {
	err := bcrypt.CompareHashAndPassword([]byte(hashedPassword), []byte(userPassword))
	if err != nil {
		return false
	} else {
		return true
	}
}